package com.keming.dao;
import com.keming.pojo.Blog;
import com.keming.pojo.show.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BlogDao {

//    <!--新增保存文章-->
    int saveBlog(Blog blog);
//    刪除
    @Delete("delete from myblog.t_blog where id=#{id}")
    void deleteBlog(Long id);
//    改
    int updateBlog(ShowBlog showBlog);
//    查
    List<BlogQuery> getAllBlogQuery();
    //查询编辑修改的文章
    ShowBlog getBlogById(Long id);
    //搜索博客管理列表
    List<BlogQuery> searchByTitleAndType(SearchBlog searchBlog);

    //-------------------------------------
    //查询首页最新博客列表信息
    List<FirstPageBlog> getFirstPageBlog();

    //查询首页最新推荐信息
    @Select("select * from myblog.t_blog where t_blog.recommend = true order by t_blog.create_time desc limit 4;")
    List<RecommendBlog> getAllRecommendBlog();

    //搜索博客列表
    List<FirstPageBlog> getSearchBlog(String query);

    //统计博客总数
    @Select("select count(*) from myblog.t_blog")
    Integer getBlogTotal();

    //统计访问总数
    @Select("select coalesce (sum(views),0) from myblog.t_blog")
    Integer getBlogViewTotal();

    //统计评论总数
    @Select("select count(*) from myblog.t_comment")
    Integer getBlogCommentTotal();

    //统计留言总数
    @Select("select count(*) from myblog.t_message")
    Integer getBlogMessageTotal();
//    ------------
    //查询博客详情
    DetailedBlog getDetailedBlog(Long id);

    //文章访问更新
    @Update("update myblog.t_blog b set b.views = b.views+1 where b.id = #{id}")
    int updateViews(Long id);

    //根据博客id查询出评论数量
    int getCommentCountById(Long id);

    //根据TypeId查询博客列表，显示在分类页面
    List<FirstPageBlog> getByTypeId(Long typeId);


}
